home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 112 / EnigmaAmiga112CD.iso / dalla rivista / awnpipe / awnp / awnp-docs / tutorials / tutorial4.rx < prev    next >
Text File  |  2000-01-02  |  7KB  |  289 lines

  1. /*Tutorial 3 for AWNPipe*/
  2.  
  3. envname='GUITutorial4'
  4. call setdefaults()
  5. call buildgui()
  6.  
  7. topipe('id 'savegad' dis 1 ref')
  8.  
  9. /*main loop*/
  10. do while ~eof(ca)
  11. call topipe('continue')
  12. in= readln(ca)
  13. parse var in in1 in2 in3 in4 .
  14. if in1='gadget' then call gadget()
  15. if in1='menu' then call menu()
  16. if in1='close' then call windowclosed()
  17. if in1='iconify' then call iconify()
  18. if in1='app' then call app()
  19. end
  20. /*end of main loop*/
  21.  
  22. exit
  23.  
  24. gadget:
  25. if in2=agegad then age=in3  Close
  26. if in2=sexgad then sex=in3
  27. if in2=knogad then knowledge=in3
  28. if in2=basgad then basic=in3
  29. if in2=aregad then arexx=in3
  30. if in2=cgad then c=in3
  31. if in2=asmgad then asm=in3
  32. /* the return from a string gadget is parsed differently since it can be more
  33. then 1 word. */
  34. if in2=namegad then do
  35. parse var in . . in3
  36. /*strip it since arexx parsing adds the leading space to the last string
  37. assignment*/
  38. name=strip(in3)
  39. if name='' then call topipe('id 'savegad' dis 1 ref')
  40. else call topipe('id 'savegad' dis 0 ref')
  41. end
  42.  
  43. if in2=dongad then do
  44. showtx(0, 'Normal exit *nname' name '*nage' age '*nsex' sex '*nknowledge' knowledge '*nbasic' basic 'arexx' arexx 'c' c 'asm' asm)
  45. exit
  46. end
  47.  
  48. if in2=resgad then call resetform()
  49. if in2=savegad then call saveform()
  50. if in2=loadgad then call loadform()
  51.  
  52. if in2=cangad then do
  53. showtx(300,'user canceled')
  54. exit
  55. end
  56.  
  57. return
  58.  
  59. windowclosed:
  60. showtx(300,'User aborted with CTRL BackSlash or closed window.')
  61. exit
  62. return
  63.  
  64. menu:
  65. if in2=0 then do
  66. if in3=0 then do
  67. if in4=0 then call setenvarc()
  68. if in4=1 then call unsetenvarc()
  69. end
  70. if in3=2 then showtx(500,' Tutorial 4 for AWNP *n  by William Parker')
  71. end
  72.  
  73.  
  74. if in2=1 then do
  75. if in3=0 then do
  76. showtx(0, 'name' name '*nage' age '*nsex' sex '*nknowledge' knowledge '*nbasic' basic 'arexx' arexx 'c' c 'asm' asm)
  77. end
  78. if in3=1 then do
  79. if in4=0 then showtx(0, 'name' name '*nage' age '*nsex' sex)
  80. if in4=1 then showtx(0, 'knowledge' knowledge '*nbasic' basic 'arexx' arexx 'c' c 'asm' asm)
  81. end
  82. end
  83. return
  84.  
  85.  
  86. setdefaults:
  87. name='unset'
  88. age=30
  89. sex=0
  90. knowledge=0
  91. basic=0
  92. c=0
  93. asm=0
  94. arexx=0
  95. return
  96.  
  97. buildgui:
  98. /* get our window size and position */
  99. call getenv()
  100.  
  101. /* Open pipe 'tut2' with GUI creation option '/xc' */
  102. call open(ca,"awnpipe:tut4/xc")
  103.  
  104. /* define the window */
  105.  
  106. /* The first line oF every GUI is the window definition. The window is titled
  107. "Tutorial 2" and its elements will be laid out verticaly (v). It has a
  108. closegadget (cg) , depthgadget (dg) , and dragbar (db). It will have spaces
  109. inbetween its gadgets (si). It will open on the topleft (tl) of the screen
  110. becoming active (a) when opened. The window can be icoified (ig) and modified
  111. (m). It is an app window (app) . It can be sized (SG) but not verticaly (fh)*/
  112.  
  113. call topipe(' "Tutorial 4" v cg dg db si a ig sg fh m app ii "tutorial4.rx" 'windowdef)
  114.  
  115. /* define the gadgets*/
  116.  
  117. call topipe(' layout b 0 v')
  118.  
  119. /* Labels are used to tell the user what information to enter in each gadget.
  120. These labels are unatached (ua) when they are defined so don't go directly
  121. into the GUI. Instead they are attached to the following gadget by the
  122. childlabel (chl) keyword. */
  123.  
  124. call topipe(' label  gt "Name: " ua')
  125. namegad=topipe('string lj chl')
  126.  
  127. call topipe(' label gt "Age: " ua')
  128. agegad=topipe('integer chl minn 5 maxn 115 arrows defn 30  weiw 0')
  129.  
  130. call topipe(' label gt "Sex: " ua')
  131. sexgad=topipe('radiobutton rl "Male|Female" chl')
  132.  
  133. call topipe(' label gt "Knowledge: " ua')
  134. knogad=topipe('chooser pu cl "Novice|Average|Good|Expert" chl')
  135.  
  136. call topipe(' label gt "Language(s): " ua')
  137.  
  138. call topipe(' layout b 0 chl')
  139. basgad=topipe('checkbox gt "Basic " chl')
  140. aregad=topipe('checkbox gt "Arexx " chl')
  141. cgad=topipe('checkbox gt "C " chl')
  142. asmgad=topipe('checkbox gt "ASM " chl')
  143. call topipe(' le')
  144.  
  145. call topipe(' le')
  146.  
  147. call topipe(' layout si so')
  148. savegad= topipe('button gt "Save" ')
  149. loadgad= topipe('button gt "Load" ')
  150. resgad= topipe('button gt "Reset Form" ')
  151. dongad= topipe('button gt "Done" c')
  152. cangad= topipe('button gt "Cancel" c')
  153. call topipe(' le')
  154.  
  155.  
  156. call topipe(' menu gt "Project|Window|$@SSnapshot|$@UUnSnapshot|-|About"')
  157. call topipe(' menu gt "Data|@AShow all data|Show part|$@PPersonal|$@SSkill"')
  158.  
  159. getfilegad=topipe('getfile gt "Select Information File" fn "t:" ua pat "#?.tut3"')
  160.  
  161. /*open the GUI window*/
  162. call topipe("open")
  163. return
  164.  
  165.  
  166. topipe:
  167. /* this routine does error checking on lines written to pipe.*/
  168.  
  169. /*get line to output*/
  170. parse arg out
  171.  
  172. /* write to the pipe*/
  173. call writeln(ca,out)
  174.  
  175. /*get responce and parse it.*/
  176. res=readln(ca)
  177. parse var res res1 res2 .
  178.  
  179. /* if all is ok return the second part of the responce (usualy the GID)*/
  180. if res1='ok' then return(res2)
  181.  
  182. /* something went wrong, we notify the user then exit */
  183. /*show problem line and responce (reponce may be just a blank line)*/
  184. say 'error from: 'out
  185. say '  responce: ' res
  186. exit
  187.  
  188. resetform:
  189. call topipe('id 'agegad' defn 30 ref')
  190. call topipe('id 'sexgad' s 0 ref')
  191. call topipe('id 'knogad' s 0 ref ')
  192. call topipe('id 'basgad' s 0 ref')
  193. call topipe('id 'aregad' s 0 ref')
  194. call topipe('id 'cgad' s 0 ref ')
  195. call topipe('id 'asmgad' s 0 ref')
  196. call topipe('id 'namegad' gt "" ref')
  197. topipe('id 'savegad' dis 1 ref')
  198. call setdefaults()
  199. return
  200.  
  201. saveform:
  202. call open(form,'t:'name'.tut3','W')
  203. call writech(form,age sex knowledge basic arexx c asm name)
  204. call close(form)
  205. return
  206.  
  207. loadform:
  208. call writeln(ca,'id 'getfilegad' fn "t:" s 1')
  209. res=readln(ca);
  210. parse var res res1 '"' filename '"'
  211. loadapp:
  212. if res1~=0 then do
  213. call open(form,filename,'R')
  214. formin=readch(form,1000)
  215. parse var formin age sex knowledge basic arexx c asm name
  216. name=substr(name,2)
  217. call close(form)
  218. /*uniconify in case its needed*/
  219. call topipe('id 0 s 64')
  220.  
  221. call topipe('id 'agegad' defn 'age' ref')
  222. call topipe('id 'sexgad' s 'sex' ref')
  223. call topipe('id 'knogad' s 'knowledge' ref ')
  224. call topipe('id 'basgad' s 'basic' ref')
  225. call topipe('id 'aregad' s 'arexx' ref')
  226. call topipe('id 'cgad' s 'c' ref ')
  227. call topipe('id 'asmgad' s 'asm' ref')
  228. call topipe('id 'namegad' gt "'name'" ref')
  229. if name='' then call topipe('id 'savegad' dis 1 ref')
  230. else call topipe('id 'savegad' dis 0 ref')
  231. end
  232. return
  233.  
  234. app:
  235. parse var in . in2
  236. filename=strip(in2)
  237. if (right(filename,5)='.tut3') then do
  238. res1=1
  239. call loadapp()
  240. end
  241. return
  242.  
  243. /* send a modify command to iconify/uniconify window and remember the current
  244. state of the window*/
  245. iconify:
  246. iconified=in2
  247. if in2=1 then call topipe('id 0 s 32')
  248. else  call topipe('id 0 s 64')
  249. return
  250.  
  251. showtx:
  252. call open(ptx,'awnpipe:tut3txt/xc')
  253. call writeln(ptx,'db dg "Tutorial 4" q cg cm m a so si ')
  254. call writeln(ptx,'label lj gt "'arg(2)'"')
  255. call writeln(ptx,'open')
  256. if arg(1)~=0 then call writeln(ptx,'tick 'arg(1))
  257. else call writeln(ptx,'m')
  258. call close(ptx)
  259. return(0)
  260.  
  261.   setenv:
  262.   call writeln(ca,'id 0 read')
  263.   windowr=readln(ca)
  264.   if open(env,'env:'envname,'W') then do
  265.   call writech(env,windowr)
  266.   close(env)
  267.   end
  268.   return(0)
  269.  
  270.   setenvarc:
  271.   call setenv()
  272.   address command 'copy env:'envname 'envarc:'envname' >nil:'
  273.   return
  274.  
  275.   unsetenvarc:
  276.   if exists('envarc:'envname) then delete('envarc:'envname)
  277.   if exists('env:'envname) then delete('env:'envname)
  278.   return
  279.  
  280.   getenv:
  281.   windowdef='tl'
  282.   if(open(env,'env:'envname,'R')) then do
  283.   windowt=readln(env)
  284.   parse var windowt wl wt ww wh .
  285.   if (datatype(wt,N) &datatype(wl,N) &datatype(ww,N) & datatype(wh,N) ) then
  286.   windowdef= 'top' wt 'left' wl 'width' ww 'height' 1
  287.   close(env)
  288.   end
  289.   return